#coding: utf-8
import time
import unittest

from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait




class Untitled(unittest.TestCase):
    def __init__(self, methodName='runTest'):
        super(Untitled, self).__init__(methodName)
        self.driver = webdriver.Firefox()

    def ajax_complete(self, driver):
        try:
            return 0 == driver.execute_script('return jQuery.active')
        except WebDriverException:
            pass

    def my_automation_test(self):
        # self.driver.get("http://dou.bars-open.ru")
        #wait for ajax items to load
        WebDriverWait(self.driver, 10).until(self.ajax_complete,  50000)
        # assert "ajax loaded string" in self.driver.page_source

    def test_untitled(self):
        driver = self.driver
        driver.get("http://dou.bars-open.ru/auth/login")
        driver.find_element_by_id("login").send_keys("admin1")
        driver.find_element_by_id("password").send_keys("admin3")
        driver.find_element_by_id("commit-button").send_keys("\n")
        self.my_automation_test()
        # driver.implicitly_wait(5)
        # print driver.current_url
        # driver.refresh()
        # driver.get("http://dou.bars-open.ru")
        time.sleep(1)
        driver.find_element_by_css_selector("div.base-desktop-image.declaration").click()
        time.sleep(1)
        driver.find_element_by_xpath(u'//div[contains(text(), "Ковалева Софья") '
                                     u'and contains(@class, "x-grid3-cell-inner")]').click()
        driver.find_element_by_xpath(u'//*[contains(text(), "Изменить") '
                                     u'and contains(@class, " x-btn-text edit_item")]').click()

    def tearDown(self):
        self.driver.quit()
